<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>渠道账号列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="__PUBLIC__/admin/favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
</head>
<include file="Admin@Index:cache" />
<body class="gray-bg contacts">
<style>
    .table-hover>tbody>tr>td{
        height:4rem;
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight" oncopy="copyval()">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>渠道账号列表</h5>
                    <div class="ibox-tools">
                        <a href="javascript:;" class="btn btn-success btn-xs" onclick="apply('','','','','','','',0)" >创建渠道账号</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="col-sm-12" style="margin-bottom: 1rem">
                        <form role="form" action="__SELF__" method="get">
                            <div class="form-group">
                                <input type="text" id="content" placeholder="" name="content" class="form-control">
                            </div>
                            <div>
                                <!--<select name="state" id="state" class="form-control m-b"  style="margin-bottom: 0;padding-top: 3px;display: inline;width: 10%;" >
                                    <option value="" >状态</option>
                                    <option value="1" <if condition="$_GET['state'] eq 1">selected</if>>未使用</option>
                                    <option value="2" <if condition="$_GET['state'] eq 2">selected</if>>已使用</option>
                                </select>-->
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit" id="search"><strong>搜索</strong></button>
                            </div>
                        </form>
                    </div>
                    <br>
                    <table class="table table-striped table-hover">
                        <tbody>
                        <tr>
                            <!--<th>渠道名</th>-->
                            <th>账号</th>
                            <th>姓名</th>
                            <th>状态</th>
                            <th>创建时间</th>
                            <th class="client-status" width="320px">操作</th>
                        </tr>
                        <foreach name="list" item="list">
                            <tr>
                                <!--<td><{$list.channel_name}></td>-->
                                <td><{$list.account}></td>
                                <td><{$list.name}></td>
                                 <td>
                                    <switch name="list.state">
                                        <case value="1">启用</case>
                                        <case value="2">禁用</case>
                                    </switch>
                                </td>
                                <td><{$list.ctime}></td>
                                <td class="client-status">
                                    <a class="btn btn-info btn-rounded " href="javascript:void(0);" onclick="apply('<{$list.account}>','<{$list.chan_id}>','<{$list.channel_name}>','<{$list.id}>','<{$list.name}>','<{$list.mobile}>','<{$list.state}>',1)">编辑</a>
                                    <a class="btn btn-danger btn-rounded" rid="<{$list.id}>" href="javascript:void(0);" onclick="del('<{$list.id}>');" >删除</a>
                                </td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                    <ul class="pagination">
                        <if condition="$tol gt 10">
                            <{$fpage}>
                        </if>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__PUBLIC__/admin/js/layer/layer.js"></script>
<script src="__PUBLIC__/admin/js/layui/layui.js"></script>
<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
<script src="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.js"></script>
<script src="__PUBLIC__/admin/js/clipboard.js"></script>
<script>
    $(document).ready(function () {
        $('.contact-box').each(function () {
            animationHover(this, 'pulse');
        });
    });

    $(document).ready(function () {
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
    });

    Array.prototype.in_array=function(e) {
        var r=new RegExp(','+e+',');
        return (r.test(','+this.join(this.S)+','));
    };

    function apply(account,chan_id,channel_name,id,name,mobile,state,n){


        var c='<{$channel}>';
        var channel=JSON.parse(c);
        html='';
        html+='<div class="modal-body" id="lists" style="height:100%">';
        html+='<form class="form-horizontal">';
//        html+='<div class="form-group">';
//        html+='<label class="col-sm-3 control-label" >选择渠道：</label>';
//        html+='<div class="col-sm-8">';
//        html+='<select class="form-control m-b" name="chan_id" id="chan_id" style="height:3rem">';
//        if(n==1){
//            html+='<option value="'+chan_id+'">'+channel_name+'</option>';
//        }else {
//            for(var i=0;i<channel.length;i++){
//                html+='<option value="'+channel[i].chan_id+'" >'+channel[i]['channel_name']+'</option>';
//            }
//        }
//        html+='</select>';
//        html+='</div>';
//        html+='</div>';
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label" >渠道账号：</label>';
        html+='<div class="col-sm-8">';
        html+='<input type="text" id="account"  value="'+account+'" placeholder="渠道账号" class="form-control"';
        if(n==1){
            html+='disabled >'
        }else {
            html+='>';
        }
        html+='</div>';
        html+='</div>';
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label" >姓名：</label>';
        html+='<div class="col-sm-8">';
        html+='<input type="text" id="name"  value="'+name+'" placeholder="姓名" class="form-control">';
        html+='</div>';
        html+='</div>';
        if(n!=1){
            html+='<div class="form-group">';
            html+='<label class="col-sm-3 control-label" >密码：</label>';
            html+='<div class="col-sm-8">';
            html+='<input type="password" id="password"  placeholder="密码" class="form-control">';
            html+='</div>';
            html+='</div>';
        }
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label" >联系电话：</label>';
        html+='<div class="col-sm-8">';
        html+='<input type="text" id="mobile"  value="'+mobile+'" placeholder="联系电话" class="form-control">';
        html+='</div>';
        html+='</div>';
        html+='<div class="form-group">';
        html+='<label class="col-sm-3 control-label">启用状态：</label>';
        html+='<div class="col-sm-8">';
        html+='<select class="form-control m-b" name="state1" id="state1" style="height:3rem">';
        var str=' selected';
        html+='<option value="1" ';
        if(state==1){
            html+=str;
        }
        html+='>启用</option>';
        html+='<option value="2" ';
        if(state==2){
            html+=str;
        }
        html+='>禁用</option>';
        html+='</select>';
        html+='</div>';
        html+='</div>';

        html+='  <div class="form-group">  ' +
            '<label class="col-sm-3 control-label">关联渠道:</label>' +
            '   <div class="col-sm-8">' ;
        for(var i=0;i<channel.length;i++) {

            html+=  ' <input type="checkbox" name="c_id" id="cid_<{$vo.id}>"  value="' + channel[i].id + '"> '+channel[i]['channel_name'];
        }
            html+=  ' </div> </div>';



        html+='</form>';
        html+='<div class="modal-footer" style="border:0">';
        html+='<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';



        if(n==1){
            html+='<a href="javascript:void(0);" onclick="applys(\''+id+'\',1);" type="button" class="btn btn-primary" >修改</a>';
        }else{
            html+='<a href="javascript:void(0);" onclick="applys(\''+id+'\',0);" type="button" class="btn btn-primary" >添加</a>';
        }
        html+='</div>';
        html+='</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['530px', '450px'],
            title: '编辑渠道',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }

    var op=1;
    var picop=1;
    function applys(id,n){
        if(op==2){
            layer.close(index);
            layer.msg('请勿重复点击',{icon:5,time:2000});
            return false;
        }
        op=2;
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        var name=$('#name').val();
        var password=$('#password').val();
        var mobile=$('#mobile').val();
        var account=$("#account").val();
        var chan_id=$("#chan_id option:selected").val();
        var state=$("#state1 option:selected").val();


        var roleArr = document.getElementsByName("c_id");
        var value = "";
        for(var i = 0; i < roleArr.length; i++){
            if(roleArr[i].checked){
                value = value+roleArr[i].value+",";
            }
        }

       var c_id=value.substring(0,value.length-1);
        if(name==""){
            layer.close(index);
            layer.msg('名字不能为空',{icon:5,time:2000});
            op=1;
            return false;
        }
        if(!(/^1[3|4|5|8|7|9][0-9]\d{4,8}$/.test(mobile))){
            layer.close(index);
            layer.alert("手机格式错误！\r\n", {
                title: '提示框',
                icon: 0,
            });
            op=1;
            return false;
        }
        if(n==1){
            if(id==""){
                layer.close(index);
                layer.msg('id不能为空',{icon:5,time:2000});
                op=1;
                return false;
            }
        }else {
            if(!(/^(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{6,}/.test(password))){
                layer.close(index);
                layer.msg('密码必须由数字、字符、特殊字符三种中的两种组成,且不少于六位',{icon:5,time:2000});
                op=1;
                return false;
            }
        }
        layer.confirm('确定要编辑渠道账号数据吗？', {
            btn: ['确定','取消'] //按钮
        },function(){
            $.post('__MODULE__/Operate/edit_cpa_account',{chan_id:c_id,id:id,account:account,name:name,mobile:mobile,state:state,password:password,c_id:c_id},function(data){
                op=1;
                layer.close(index);
                if(data.code=='1001'){
                    window.location.reload();
                }else{
                    if(data.status=='0'){
                        layer.msg(data.info,{time:2000,icon:5});
                    }else{
                        layer.msg(data.result,{time:2000,icon:5});
                    }
                }
            });
        }, function(){
            op=1;
                layer.close(index);
            });
    }

    //删除
    function del(id){
        if(op==2){
            layer.close(index);
            layer.msg('请勿重复点击',{icon:5,time:2000});
            return false;
        }
        op=2;
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        layer.confirm('是否确定删除该渠道账号',function(){
            $.post('__MODULE__/Operate/del_cpa_account',{id:id},function(data){
                op=1;
                layer.closeAll();
                if(data.code=='1001'){
                    window.location.reload();
                }else{
                    if(data.status=='0'){
                        layer.msg(data.info,{time:2000,icon:5});
                    }else{
                        layer.msg(data.result,{time:2000,icon:5});
                    }
                }
            });
        });
    }


    function copyval() {
//        event.returnValue = false;
        var content = window.getSelection().toString();
        $.post('__MODULE__/Mypublic/copy_all', {content:content}, function (data) {
            if (data.code == '1001') {
            } else {
                console.log(data);
            }
        });
//        console.log(content)
    }
</script>


</body>

</html>
